<?php
/**
 * Magento Enterprise Edition
 *
 * NOTICE OF LICENSE
 *
 * This source file is subject to the Magento Enterprise Edition End User License Agreement
 * that is bundled with this package in the file LICENSE_EE.txt.
 * It is also available through the world-wide-web at this URL:
 * http://www.magento.com/license/enterprise-edition
 * If you did not receive a copy of the license and are unable to
 * obtain it through the world-wide-web, please send an email
 * to license@magento.com so we can send you a copy immediately.
 *
 * DISCLAIMER
 *
 * Do not edit or add to this file if you wish to upgrade Magento to newer
 * versions in the future. If you wish to customize Magento for your
 * needs please refer to http://www.magento.com for more information.
 *
 * @category    design
 * @package     rwd_enterprise
 * @copyright Copyright (c) 2006-2015 X.commerce, Inc. (http://www.magento.com)
 * @license http://www.magento.com/license/enterprise-edition
 */
/** @var $this Enterprise_Rma_Block_Return_View */
?>
<?php
    $_rma = $this->getRma();
    $_order = $this->getOrder();
    $additionalData = $this->getAdditionalData();
?>

<div class="page-title">
    <h1><?php echo $this->__('RMA') ?> #<?php echo $_rma->getIncrementId()?> - <?php echo $this->escapeHtml($_rma->getStatusLabel()) ?></h1>
</div>

<div class="col2-set">
    <div class="box">
        <div class="box-content">
            <div class="col-1 rma-view">
                <div class="info-box">
                    <h3 class="box-title"><?php echo $this->__('Request Information') ?></h3>
                    <p class="box-content">
                        <?php echo $this->__('ID') ?>: <?php echo $this->escapeHtml($_rma->getIncrementId()) ?><br />
                        <?php echo $this->__('Order ID') ?>: <a href="<?php echo $this->getOrderUrl($_rma) ?>"><?php echo $this->escapeHtml($_rma->getOrderIncrementId()) ?></a><br />
                        <?php echo $this->__('Date Requested') ?>: <?php echo Mage::helper('enterprise_rma')->getFormatedDate($_rma->getDateRequested()) ?><br />
                        <?php echo $this->__('Email Address') ?>: <?php echo $this->escapeHtml($_order->getCustomerEmail()) ?><br />
                        <?php echo $this->__('Contact Email Address') ?>: <?php echo $this->escapeHtml($_rma->getCustomerCustomEmail()) ?>
                    </p>
                </div>
            </div>
            <div class="col-2 rma-view">
                <div class="info-box">
                    <h3 class="box-title"><?php echo $this->__('Shipping Address') ?></h3>
                    <address class="box-content">
                        <?php echo $this->getAddress() ?>
                    </address>
                 </div>
            </div>
        </div>
    </div>
</div>
<div class="wrapper"></div>


<span id="rma-please-wait" class="please-wait" style="display:none;">
    <img src="<?php echo $this->getSkinUrl('images/opc-ajax-loader.gif') ?>" alt="" class="v-middle" /> <?php echo $this->__('Please wait, loading...') ?>
</span>
<?php $trackingNumbers = $this->getTrackingNumbers() ?>
<?php if ($this->isPrintShippingLabelAllowed() || $trackingNumbers->count()): ?>
    <form method="post" id="rma_track_info">
        <div class="box">
            <div class="box-content">
                <div class="info-box">
                    <h3 class="box-title"><?php echo $this->__('Shipping and Tracking Information') ?></h3>
                    <div class="box-content">
                        <div class="a-right">
                        <?php if ($trackingNumbers->count()): ?>
                            <a class="f-left"
                                href="#"
                                onclick="popWin('<?php echo $this->helper('enterprise_rma')->getTrackingPopupUrlBySalesModel($this->getRma()) ?>','trackshipment','width=800,height=600,top=0,left=0,resizable=yes,scrollbars=yes'); return false;"
                                title="<?php echo $this->quoteEscape($this->__('Track this shipment')) ?>">
                                    <?php echo $this->__('Track this shipment') ?>
                            </a>
                        <?php endif ?>
                        <?php if ($this->canShowButtons()): ?>
                            <?php echo $this->getPrintShippingLabelButton() ?>
                            <?php echo $this->getShowPackagesButton() ?>
                        <?php endif; ?>
                        </div>
                        <div class="clear wrapper"></div>
                        <table class="data-table" id="track-info-table">
                            <col width="230" />
                            <col width="350" />
                            <col width="80" />
                            <thead>
                                <tr>
                                    <th><span class="nobr"><?php echo $this->__('Carrier') ?></span></th>
                                    <th><span class="nobr"><?php echo $this->__('Number') ?></span></th>
                                    <th><span class="nobr"><?php echo $this->__('Action') ?></span></th>
                                </tr>
                            </thead>
                            <tbody id="track-info-tbody">
                                <?php echo $this->getTrackingInfo('tracking') ?>
                            </tbody>
                            <?php if ($this->isPrintShippingLabelAllowed()): ?>
                                <tfoot>
                                    <tr>
                                        <td>
                                            <select name="tracking_carrier_select" id="tracking_carrier_select" class="input-text required-entry f-fix">
                                                <option value = ""></option>
                                                <?php foreach($this->getCarriers() as $key => $value): ?>
                                                    <option value="<?php echo $key ?>"><?php echo $this->escapeHtml($value) ?></option>
                                                <?php endforeach ?>
                                            </select>
                                        </td>
                                        <td>
                                            <input type="text" class="input-text required-entry f-fix" value="" name="tracking_number_input" id="tracking_number_input">
                                        </td>
                                        <td>
                                            <button type="button" class="button" onclick="addTrackNumber()" title="<?php echo $this->quoteEscape($this->__('Add')) ?>"><span><span><?php echo $this->__('Add') ?></span></span></button>
                                        </td>
                                    </tr>
                                </tfoot>
                            <?php endif ?>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </form>
    <script type="text/javascript">
    //<![CDATA[
        var trackDataForm = new VarienForm('rma_track_info', false);
        decorateTable('track-info-table');

        function addTrackNumber() {
            if (trackDataForm.validator.validate()) {
                new Ajax.Updater('track-info-tbody', '<?php echo $this->getAddLabelUrl() ?>', {
                    onCreate: function() { $('rma-please-wait').show() },
                    onComplete: function() {
                        $('rma-please-wait').hide();
                        decorateTable('track-info-table');
                    },
                    method: 'post',
                    parameters : {
                        carrier: $("tracking_carrier_select").value,
                        number: $("tracking_number_input").value
                    }
                });
            }
        }
    //]]>
    </script>
    <div class="wrapper"></div>
<?php endif ?>

<h3 class="box-title"><?php echo $this->__('Items Return Requested For') ?></h3>
<table class="data-table linearize-table-large" id="my-returns-items-table">
    <col width="200" />
    <col width="200" />
    <col />
    <col />
    <col />
    <col />
    <col />
    <col />
    <thead>
        <tr>
            <th><span class="nobr"><?php echo $this->__('Product Name') ?></span></th>
            <th><?php echo $this->__('SKU') ?></th>
            <th><?php echo $this->__('Condition') ?></th>
            <th><?php echo $this->__('Resolution') ?></th>
            <th><span class="nobr"><?php echo $this->__('Request Qty') ?></span></th>
            <th><?php echo $this->__('Qty') ?></th>
            <th><?php echo $this->__('Status') ?></th>
            <th></th>
        </tr>
    </thead>
    <tbody>
        <?php foreach ($this->getItems() as $key=>$item): ?>
        <tr>
            <td>
                <?php echo $this->escapeHtml($item->getProductName()) ?>
                <?php if($_options = $this->getItemOptions($item)): ?>
                <dl class="item-options">
                <?php foreach ($_options as $_option) : ?>
                    <dt><?php echo $this->escapeHtml($_option['label']) ?>:</dt>
                    <dd><?php echo $_option['value'] ?></dd>
                <?php endforeach; ?>
                </dl>
                <?php endif; ?>
            </td>

            <td data-rwd-label="<?php echo $this->__('SKU') ?>"><?php echo $this->escapeHtml($item->getProductSku()) ?></span></td>

            <td data-rwd-label="<?php echo $this->__('Condition') ?>"><?php echo $this->escapeHtml($this->getAttributeValue($item->getId(), 'condition')) ?></td>

            <td data-rwd-label="<?php echo $this->__('Resolution') ?>"><?php echo $this->escapeHtml($this->getAttributeValue($item->getId(), 'resolution')) ?></td>

            <td data-rwd-label="<?php echo $this->__('Request Qty') ?>"><?php echo $this->escapeHtml($this->helper('enterprise_rma')->parseQuantity($item->getQtyRequested(), $item)); ?></td>
            <td data-rwd-label="<?php echo $this->__('Qty') ?>"><?php echo $this->escapeHtml($this->helper('enterprise_rma')->getQty($item));?></td>

            <td data-rwd-label="<?php echo $this->__('Status') ?>"><span class="nobr"><?php echo $this->escapeHtml($item->getStatusLabel()) ?></span></td>

             <td>
                <a id="as_<?php  echo $key ?>" href="javascript:void(0)" onclick="showHiddenForm(<?php  echo $key ?>)"><?php  echo $this->__('Show Details') ?></a>
                <a id="ah_<?php  echo $key ?>" style="display:none" href="javascript:void(0)" onclick="hideHiddenForm(<?php  echo $key ?>)"><?php  echo $this->__('Hide Details') ?></a>
            </td>

        </tr>
        <tr id="shf_<?php  echo $key ?>" style="display:none">
            <td colspan="8" style="background:#F5F5F5;">
                <div style="display:inline; float:left;width:40%;"><?php echo $this->__('Questions') ?>:</div>
                <div style="display:inline; float:left;width:40%;"><?php echo $this->__('Answers') ?>:</div>
                <div style="clear: both;"></div>
                <?php $i = 0; ?>
                <?php foreach($this->getRealValueAttributes($item->getId()) as $code=>$attribute): ?>
                    <?php if (!in_array($code, $this->getAttributeFilter()) && !empty($attribute['value']) && $this->getAttributeLabel($item->getId(), $code)): $i++;?>
                        <div style="display:inline; float:left;width:40%;padding-left:20px"><li><?php echo $this->getAttributeLabel($item->getId(), $code) ?></li></div>
                        <div style="display:inline; float:left;width:40%;"><li><?php echo $this->getAttributeValue($item->getId(), $code) ?></li></div>
                        <div style="clear: both;"></div>
                    <?php endif; ?>
                <?php endforeach; ?>
            </td>
        </tr>
        <?php if (!$i): ?>
            <script type="text/javascript">
            //<![CDATA[
                $('shf_'+<?php echo $key?>).remove();
                $('as_'+<?php echo $key?>).remove();
                $('ah_'+<?php echo $key?>).remove();
            //]]>
            </script>
        <?php endif; ?>
        <?php endforeach; ?>

        <!-- <tr><td colspan="8"></td></tr> -->
    </tbody>
</table>
<script type="text/javascript">
//<![CDATA[
    decorateTable('my-returns-items-table');

    function showHiddenForm(key)
    {
        $('shf_'+key).show();
        $('as_'+key).hide();
        $('ah_'+key).show();
    }
    function hideHiddenForm(key)
    {
        $('shf_'+key).hide();
        $('as_'+key).show();
        $('ah_'+key).hide();
    }
//]]>
</script>
<div class="wrapper"></div>
<br>
<form method="post" id="rma_comment" action="<?php echo $this->getSubmitUrl() ?>">
    <div class="box">
        <div class="box-content">
            <div class="info-box">
                <h3 class="box-title"><?php echo $this->__('Leave Comment') ?></h3>
                <p class="box-content">
                    <label><?php echo $this->__('Comment Text') ?></label>
                    <textarea id="rma_comment_text" style="height:6em;min-width:100%;width:99%;" cols="5" rows="3" name="comment" class="input-text required-entry"></textarea>
                </p>
                <div class="box-content buttons-set">
                    <button type="submit" class="button" id="submit.save"><span><span><?php echo $this->__('Submit Comment')?></span></span></button>
                </div>
                <div class="clear"></div>
                <div class="divider"></div>
                <ul class="note-list box-content">
                    <?php $_comments = $this->getComments(); ?>
                    <?php if (!empty($_comments)): ?>
                    <?php foreach($_comments as $_comment): ?>
                        <?php if ($_comment->getIsVisibleOnFront()): ?>
                        <li>
                            <?php echo $this->formatDate($_comment->getCreatedAt()) ?> <?php echo $this->formatTime($_comment->getCreatedAt()) ?>
                            <span class="separator">|</span>

                            <?php if ($_comment->getIsAdmin()): ?>
                                <?php echo $this->__('Customer Service')?>
                            <?php else: ?>
                                <?php echo $this->escapeHtml($this->getCustomerName())?>
                           <?php endif; ?>

                            <br />

                            <span>
                                <?php echo nl2br($this->escapeHtml($_comment->getComment())); ?>
                            </span>

                            <div class="divider"></div>
                        </li>
                        <?php endif; ?>
                    <?php endforeach; ?>
                    <?php endif; ?>
                </ul>
            </div>
        </div>
    </div>
</form>
<script type="text/javascript">
//<![CDATA[
    var dataForm = new VarienForm('rma_comment', true);
//]]>
</script>
